package com.ayoka.parenting.ui.meditation.index;

import com.ayoka.parenting.Constants;
import com.ayoka.parenting.bean.BaseResponse;
import com.ayoka.parenting.bean.MeditationIndexDataBean;
import com.ayoka.parenting.http.API;
import com.ayoka.parenting.http.HttpBeanInterceptCallback;
import com.ayoka.parenting.interf.CallbackUtil;
import com.ayoka.parenting.interf.RequestCallback;
import com.ayoka.parenting.mvp.BasePresenter;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: MeditationIndexModel&.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class MeditationIndexModel implements MeditationIndexContract.Model{

    @Override
    public void getMeditationIndexData(final BasePresenter presenter, final RequestCallback<MeditationIndexDataBean> callback) {
        API.getMeditationIndexData(presenter, new HttpBeanInterceptCallback<BaseResponse<MeditationIndexDataBean>>() {
            @Override
            public void onSuccess(BaseResponse<MeditationIndexDataBean> response) {
                CallbackUtil.notifySuccess(callback, response.data);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (errorCode == Constants.WX_ERROR_TOKEN) {
                    getMeditationIndexData(presenter, callback);
                    return;
                }
                CallbackUtil.notifyFailure(callback, errorCode, errorMessage);
            }
        });
    }
}
